package com.tencent.sr.iris.basic.saas.service.model.advisor;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.tencent.sr.iris.activity.interfaces.response.group.AdvisorBoardSprintSecondResponse;
import com.tencent.sr.iris.basic.saas.common.enums.IrisAuditStatusEnum;
import com.tencent.sr.iris.basic.saas.common.enums.IrisTaskTypeEnum;
import com.tencent.sr.iris.basic.saas.common.utils.CommonUtils;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Optional;

@Data
@Slf4j
@ColumnWidth(15)
@ApiModel(value = "导师身份-二级团长任务列表(多目标冲刺赛)导出信息")
public class AdvisorBoardSaleNumSprintExportInfo extends AdvisorBoardSprintExportInfo {

    @ExcelProperty(value = "实时进度", index = 6)
    private String bonusRuleStage;

    @ExcelProperty(value = "销售额", index = 7)
    private Double saleAmount;

    @ExcelProperty(value = "订单量", index = 8)
    private Integer orderNum;

    @ExcelProperty(value = "销售件数", index = 9)
    private Integer saleNum;

    @ExcelProperty(value = "佣金", index = 10)
    private Double validCommissionBillCommissionFee;

    @ExcelProperty(value = "用户数", index = 11)
    private Integer validInviteUserNum;

    @ExcelProperty(value = "预估奖励金", index = 12)
    private Double predictAwardAmount;

    @ExcelProperty(value = "实际奖励金", index = 13)
    private Double awardAmount;

    @ExcelProperty(value = "审核状态", index = 14)
    private String auditStatus;

    @Override
    public void readFromSearchResponseData(AdvisorBoardSprintSecondResponse response) {
        super.readFromSearchResponseData(response);

        Integer taskTargetEvaluation = response.getTaskTargetEvaluation();
        Double commissionTimes = Optional.ofNullable(response.getCommissionTimes()).orElse(0d);
        boolean magnify = IrisTaskTypeEnum.SALES_VOLUME_SPRINT_MAGNIFY.getCodes().contains(taskTargetEvaluation)
                || IrisTaskTypeEnum.GMV_SPRINT_MAGNIFY.getCodes().contains(taskTargetEvaluation);
        String msg = magnify && commissionTimes != 0 ? "翻至" + commissionTimes + "倍"
                : magnify ? "未翻倍"
                : "进行至" + response.getBonusRuleStage() + "阶段";
        this.setBonusRuleStage(msg);

        this.setSaleAmount(CommonUtils.longToDouble(response.getValidGmv()));
        this.setValidCommissionBillCommissionFee(CommonUtils.longToDouble(response.getValidCommissionBillCommissionFee()));
        this.setOrderNum(response.getValidOrderNum());
        this.setValidInviteUserNum(response.getValidInviteUserNum());
        this.setSaleNum(response.getValidGoodsNum());

        this.setPredictAwardAmount(CommonUtils.longToDouble(response.getPredictAwardAmount()));
        this.setAwardAmount(CommonUtils.longToDouble(response.getAwardAmount()));
        this.setAuditStatus(IrisAuditStatusEnum.getByStatus(response.getAuditStatus()));
    }

}
